//
//  PiecesRecordCell.m
//  J智现场
//
//  Created by song on 2018/1/26.
//  Copyright © 2018年 王长飞. All rights reserved.
//

#import "InsuranceCell.h"

@interface InsuranceCell()
{
    UIImageView *pictureImg;
    UILabel *goodsnamelab ;
    UIView *tagView ;
}
@end

@implementation InsuranceCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath
{
    NSString *cellID = [NSString stringWithFormat:@"cellID%zd%zd",indexPath.section,indexPath.row];
    InsuranceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[InsuranceCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundView = nil ;
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self buildUI];
    }
    return self;
}

- (void)buildUI
{
    pictureImg = [[UIImageView alloc]initWithFrame:CGRectMake(6, 10, 100, 70)];
    [pictureImg setCornerRedius:3];
    [self addSubview:pictureImg];
    
    goodsnamelab = [[UILabel alloc]initWithFrame:CGRectMake(pictureImg.right+8, 5, SCREEN_WIDTH-pictureImg.right-80-12, 50)];
    goodsnamelab.font = KFontSmall;
    goodsnamelab.textColor = kTitleColor_black;
    goodsnamelab.numberOfLines = 3;
    [self addSubview:goodsnamelab];
    
    tagView = [[UIView alloc]initWithFrame:CGRectMake(goodsnamelab.left, 62, SCREEN_WIDTH-goodsnamelab.left, 20)];
    [self addSubview:tagView];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(5, 89, SCREEN_WIDTH-80-10, 0.5)];
    line.backgroundColor = UIColorFromRGB1(0xE5B580);
    [self addSubview:line];
    
}

- (void)setModel:(InsuranceDataList *)model{

    _model = model;

    [pictureImg sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:kDefaultImage];
    goodsnamelab.text = model.title;
    goodsnamelab.height = [PublicUtils getStringSizeWith:model.title Width:goodsnamelab.width Font:goodsnamelab.font]+10;

    NSString *idsName = model.thirdCategoryIdsName;
    if(!ISEMPTY(idsName)){
        NSArray *aArray  = [NSArray array];
        if([idsName containsString:@","]){
            aArray = [idsName componentsSeparatedByString:@","];
        }else{
            aArray = @[idsName];
        }
        
        UILabel *prelab;
        CGFloat left = 0;
        for (int i = 0; i<aArray.count; i++) {
            if(i !=0 ){
                left = prelab.right+3;
            }
            UILabel *tag = [[UILabel alloc]initWithFrame:CGRectMake(left ,2, 30, 16)];
            tag.font = [UIFont systemFontOfSize:10];
            tag.text = aArray[i];
            tag.textColor = kTitleColor_midden;
            tag.textAlignment = NSTextAlignmentCenter;
            tag.backgroundColor = UIColorFromRGB1(0xfffde0bb);
            [tag setCornerRedius:4];
            tag.width = [PublicUtils getLabelWidthWithString:tag.text font:tag.font]+6;
            prelab = tag;
            [tagView addSubview:tag];
        }
    }
}

@end
